/*****************************************************
Copyright (C) 2020. All rights reserved.
File name     ：SelectionSort.c
Version       ：v1.0
Author        ：zhengqijun
Date          ：2020-04-09
Function List ：
Description   ：Selection Sort
******************************************************/

#include "SelectionSort.h"
#include <stdbool.h>

// Static Function Lists
static void Swap(ElementType *Lhs, ElementType *Rhs);

static void Swap(ElementType *Lhs, ElementType *Rhs) {
    ElementType Tmp;

    Tmp = *Lhs;
    *Lhs = *Rhs;
    *Rhs = Tmp;
}

void SelectionSort(ElementType A[], int N) {
    int i;
    int j;
    int min;

    for (i = 0; i < N - 1; ++i) {
        min = i;
        for (j = i + 1; j < N; ++j) {
            if (A[j] < A[min]) {
                min = j;
            }
        }

        Swap(&A[i], &A[min]);
    }
}

// EOF

